package org.jaaksi.androidforflutterdemo

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import io.flutter.embedding.android.FlutterActivity
import kotlinx.android.synthetic.main.activity_main.btn_flutter_fragment
import kotlinx.android.synthetic.main.activity_main.btn_request
import kotlinx.android.synthetic.main.activity_main.btn_request2
import kotlinx.android.synthetic.main.activity_main.btn_start_flutter_page

class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    btn_start_flutter_page.setOnClickListener {
      startActivity(
//        FlutterActivity.withNewEngine().initialRoute("home_page").build(this)
        // 通过缓存Engine，加快flutter启动
        FlutterActivity
          .withCachedEngine(home_page_engine_id)
          .build(this)
      )
    }

    btn_flutter_fragment.setOnClickListener {
      startActivity(Intent(this, TestFlutterFragment::class.java))
    }


    btn_request.setOnClickListener {
      startActivity(
        FlutterActivity.withNewEngine().initialRoute("flutterpage://page1?url=www.baidu.com&page=3")
          .build(this)
      )
    }

    btn_request2.setOnClickListener {
      startActivity(
        FlutterActivity.withNewEngine().initialRoute("flutterpage://page2?url=www.baidu.com&page=3")
          .build(this)
      )
    }
  }

}